<?php
require('includes/top.php');
$modelname_array = explode('-',$_POST['type']);
$laptop_id = $modelname_array[0];
$user_id = $modelname_array[1];


$query=mysql_query("Select laptop_id,received from return_laptop where laptop_id='".$laptop_id."' and user_id='".$user_id."'");
while($row=mysql_fetch_array($query))
{
	if($row['received']=="0")
	{
		$sql="UPDATE return_laptop set`received`='1' WHERE laptop_id='".$laptop_id."' and user_id='".$user_id."'";
		$result=mysql_query($sql);
	}
}

if(isset($_POST["type_acc"]) && !empty($_POST["type_acc"])){	
					  $Acc_name=array_values($_POST["type_acc"]);
					  									
	 				  $count=sizeof($Acc_name);										  
					  for($i=0;$i<=$count;$i++){					  						  					  
					     if(trim($Acc_name[$i])!=''){
						    $AccName=addslashes(trim($Acc_name[$i]));	
						
		$query1=mysql_query("Select * from laptop_acc where acc_name='".$AccName."'");
		$rows=mysql_fetch_array($query1);	
		$AccId = $rows['acc_id'];																																
				$sql1="UPDATE returned_laptops_acc set`received`='1' WHERE laptop_id='".$laptop_id."' and accessories_id='".$AccId."' and user_id='".$user_id."'";
$result1=mysql_query($sql1);
																																						
																				
						 }										
					  
		}
					
	  }	 
	  
	  
if(isset($_POST["acc"]) && !empty($_POST["acc"])){	
					  $Acc=array_values($_POST["acc"]);
					  $Acc_id=array_values($_POST["acc_id"]);
					  $depot_loc=array_values($_POST["depot_loc"]);
					  									
	 				  $count=sizeof($Acc);										  
					  for($i=0;$i<=$count;$i++){					  						  					  
					     if(trim($Acc[$i])!=''){
						    $AccName=addslashes(trim($Acc[$i]));
							$Acc_id=addslashes(trim($Acc_id[$i]));
							$DepotLoc=addslashes(trim($depot_loc[$i]));	
																	
				$sql1="UPDATE return_accessories set `received`='1' WHERE laptop_id='".$laptop_id."' and user_id='".$user_id."'";
$result1=mysql_query($sql1);
																								
																				
						 }										
					  
		}
					
	  }
	  
    //added here for substitute laptop 
	
	  $slaptop_id=$_POST['typesub'];
	 
$squery=mysql_query("Select laptop_id,received from substitute_laptop where laptop_id='".$slaptop_id."' and user_id='".$user_id."' AND Status='Return'");
while($row1=mysql_fetch_array($squery))
{
    if($row1[1]=="0")
	{
		$ssql="UPDATE substitute_laptop  set`received`='1' WHERE laptop_id='".$slaptop_id."' and user_id='".$user_id."' AND Status='Return'";
		$sresult=mysql_query($ssql);
	}
}
 

if($result1>0)
{
header('Location:tech_checklist.php?v=success');
}
else
{
header('Location:tech_checklist.php?v=err');
}


?>